package com.itheima.homework;
/*
3、
【编号：1103】
    定义动物类
    属性：年龄，颜色
    生成空参有参构造，set和get方法
    行为：eat(String something)方法(无具体行为,不同动物吃的方式和东西不一样,something表示吃的东西)
    定义狗类继承动物类，行为：eat(String something)方法,看家lookHome方法(无参数)
    定义猫类继承动物类，行为：eat(String something)方法,逮老鼠catchMouse方法(无参数)
    定义Person类
    生成空参有参构造，set和get方法
    属性：（姓名，年龄）
    行为：keepPet( ????? ,String something)方法
    ​ 功能：喂养【宠物狗】和【宠物猫】，问号处自己思考，something表示喂养的东西
    定义测试类，使用Perosn对象调用keepPet方法，实现运行结果
    运行结果：
    年龄为30岁的老王养了一只黑颜色的2岁的宠物
    2岁的黑颜色的狗两只前腿死死的抱住骨头猛吃
    年龄为25岁的老李养了一只灰颜色的3岁的宠物
    3岁的灰颜色的猫眯着眼睛侧着头吃鱼
 */
public class Test03 {
    public static void main(String[] args) {
        Animal a = new Dog(2,"黑颜色");
        Animal b = new Cat(3,"灰颜色");
        Person03 p1 = new Person03("老王",30);
        Person03 p2 = new Person03("老李",25);
        p1.keepPet(a,"骨头");
        p2.keepPet(b,"鱼");
    }
}
abstract class Animal{
    private int age;
    private String color;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public Animal() {
    }

    public Animal(int age, String color) {
        this.age = age;
        this.color = color;
    }

    public abstract void eat(String something);

}

class Dog extends Animal{

    @Override
    public void eat(String something) {
        System.out.println(this.getAge()+"岁的"+this.getColor()+"的狗两只前腿死死的抱住"+something+"猛吃");
    }

    public void lookHome(){
        System.out.println("狗狗会看家");
    }

    public Dog() {
    }

    public Dog(int age, String color) {
        super(age, color);
    }


}

class Cat extends Animal{

    public Cat() {
    }

    public Cat(int age, String color) {
        super(age, color);
    }

    public void catchMouse(){
        System.out.println("猫猫逮老鼠");
    }
    @Override
    public void eat(String something) {
        System.out.println(this.getAge()+"岁的"+this.getColor()+"的猫眯着眼睛侧着头吃"+something);
    }
}

class Person03{
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Person03() {
    }

    public Person03(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void keepPet(Animal animal,String something){
        System.out.println("年龄为"+this.age+"岁的"+this.name+"养了一只"+animal.getColor()+"的"+animal.getAge()+"岁的宠物");
        animal.eat(something);
    }
}


